package uploadServer;

import java.io.File;

import javax.swing.filechooser.FileFilter;

public class PNGorJPGFilter extends FileFilter{
	String[] extensionImg = {"png" , "jpg"};
	
	public boolean accept(File file) {
		if (file.isDirectory()) {
            return true;
        }
		
        String filename = file.getName();
        for (int i = 0; i < extensionImg.length; i++) {
            String extension = extensionImg[i];
            if (filename.endsWith(extension) && 
            		(filename.charAt(filename.length() - extension.length() - 1) == '.')) {
              return true;
            }
        }
        return false;
    }
	
    public String getDescription() {
    	String extension= "*." ;
    	for (int i = 0; i < extensionImg.length; i++) {
    		if(extensionImg[i] == extensionImg[extensionImg.length - 1]){
    			extension += extensionImg[i];
    		}else{
    			extension += extensionImg[i]+", *.";
    		}
    	}
        return "Image("+extension+")";
    }
}

